package acm.pta6;

import java.util.Scanner;

public class 外星人的一天 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n = sc.nextInt();
        while (n-->0){
            int day = sc.nextInt();
            String next = sc.next();
            if (day==0){
                System.out.println(day+" "+next);
                continue;
            }
            String[] read = next.split(":");
            int h=Integer.parseInt(read[0]);
            int m=Integer.parseInt(read[1]);
            int res=m+h*60+(day-1)*60*24;
            res=res>>1;
            m=res%60;
            res/=60;
            h=res%24;
            day=res/24;
            System.out.println(String.format("%d %02d:%02d",day+1,h,m));
        }
    }
}
